<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&#x00A0;">
]>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:umbraco.examine="urn:umbraco.examine"
  exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.examine ">


  <xsl:output method="html" omit-xml-declaration="yes"/>

  <xsl:param name="currentPage"/>
  <xsl:param name="rootNode" select="$currentPage/ancestor-or-self::Intro"/>

  <xsl:template match="/">
    <section id="content">
      <div class="container_12">
        <div class="wrapper">
          <article class="grid_8">
            <h2 class="border1">
              <xsl:value-of select="$currentPage/commonName"/>
            </h2>
            <xsl:variable name="searchString" select ="umbraco.library:RequestQueryString('s')" />
            <xsl:if test="$searchString!=''">
              <h5>
                Resultados encontrados para a pequisa: <xsl:value-of select="$searchString"/>
              </h5>
              <div>
                <xsl:for-each select="$rootNode/descendant::*[@id!='']">
                  <xsl:variable name="nodeContent" select="Exslt.ExsltStrings:lowercase(.)"></xsl:variable>
                  <xsl:if test="contains($nodeContent,Exslt.ExsltStrings:lowercase($searchString))">
                    <div class="extra-wrap">
                      <a href="{umbraco.library:NiceUrl(@id)}" class="link3">
                          <xsl:choose>
                            <xsl:when test="contentTitle!=''">
                              <xsl:value-of select="contentTitle"/>
                            </xsl:when>
                            <xsl:when test="contentTitle='' and commonName!=''">
                              <xsl:value-of select="commonName"/>
                            </xsl:when>
                            <xsl:otherwise>
                              <xsl:value-of select="@nodeName"/>
                            </xsl:otherwise>
                          </xsl:choose>
                        </a>
                        <p>
                          <xsl:variable name="currentParentNode" select="umbraco.library:GetXmlNodeById(@parentID)"></xsl:variable>
                          <xsl:variable name="contentType">
                            <xsl:choose>
                              <xsl:when test="$currentParentNode/commonName != ''">
                                <xsl:value-of select="$currentParentNode/commonName"/>
                              </xsl:when>
                              <xsl:otherwise>
                                <xsl:value-of select="$currentParentNode/@nodeName"/>
                              </xsl:otherwise>
                            </xsl:choose>
                          </xsl:variable>
                          <xsl:choose>
                            <xsl:when test="contentSummary!=''">
                              <xsl:value-of select="$contentType"/> | <xsl:value-of select="contentSummary"/>
                            </xsl:when>
                            <xsl:when test="contentSummary='' and contentBody!=''">
                              <xsl:value-of select="$contentType"/> | <xsl:value-of select ="umbraco.library:TruncateString(contentBody, 140,'...')" disable-output-escaping="yes" />
                            </xsl:when>
                            <xsl:otherwise>
                              <xsl:value-of select="$contentType"/>
                            </xsl:otherwise>
                          </xsl:choose>
                        </p>                      
                    </div>
                  </xsl:if>
                </xsl:for-each>
              </div>
            </xsl:if>
          </article>
        </div>
      </div>
    </section>
  </xsl:template>
</xsl:stylesheet>